%% Pre setup
time_delta = 1000;
start_time = 0;

%% Create random set of tasks

% Create some track update tasks
for i = 1:100
  priority = ceil(rand()*30);
  min_duration = 10 + ceil(rand()*10);
  max_duration = 20 + ceil(rand()*10);
  soonest_start_time = ceil(rand()* 10 * time_delta);
  latest_end_time = soonest_start_time + max(ceil(rand() * 10 * time_delta), time_delta);
  update_track_task(i) = SS_Task(sprintf('U%i',i), priority,... 
    min_duration, max_duration, soonest_start_time, latest_end_time);
end

% Create some id tasks
for i = 1:100
  priority = ceil(rand()*30);
  min_duration = 100 + ceil(rand()*10);
  max_duration = 200 + ceil(rand()*10);
  soonest_start_time = ceil(rand()* 30 * time_delta);
  latest_end_time = soonest_start_time + max(ceil(rand() * 10 * time_delta), time_delta);
  id_track_task(i) = SS_Task(sprintf('I%i',i), priority,... 
    min_duration, max_duration, soonest_start_time, latest_end_time);
end

% Create some search tasks
for i = 1:100
  priority = ceil(rand()*30);
  min_duration = 100 + ceil(rand()*10);
  max_duration = 200 + ceil(rand()*10);
  soonest_start_time = ceil(rand()* 30 * time_delta);
  latest_end_time = soonest_start_time + max(ceil(rand() * 30 * time_delta), time_delta);
  search_volume_task(i) = SS_Task(sprintf('S%i',i), priority,... 
    min_duration, max_duration, soonest_start_time, latest_end_time);
end

%% Pack all the tasks
all_tasks = [search_volume_task id_track_task update_track_task];

i = 1;
lost_time = 0;
while (size(all_tasks, 2) > 0)
  timeline(i) = SS_Timeline(sprintf('T%i',i), start_time, time_delta, lost_time);
  [timeline(i), all_tasks] =  SS_Timeline_Brick_Pack(timeline(i), all_tasks);
  lost_time = timeline(i).spill_over_time;
  start_time = start_time + time_delta;
  i = i + 1;
end

%% Indicators
total_assigned_tasks = 0;
for t = 1:size(timeline, 2)
  tasks_per_timeline(t) = size(timeline(t).tasks, 2);
  total_assigned_tasks = total_assigned_tasks + tasks_per_timeline(t);
end



